package com.daocao.hua.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.ImageView;

import com.daocao.hua.util.Util;

/**
 * Created by xsooy-pc on 2017/5/10.
 */

public class ProportionImageView extends ImageView {
    public ProportionImageView(Context context) {
        super(context);
    }

    public ProportionImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ProportionImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        DisplayMetrics dm = Util.getDisplayMetrics(getContext());
        int width = dm.widthPixels;
        int height = width * 4 / 15;
        setMeasuredDimension(width, height);
    }
}
